//
//  WTPictureCell.m
//  OneDay
//
//  Created by lanou on 16/1/14.
//  Copyright © 2016年 小明. All rights reserved.
//

#import "WTPictureCell.h"
#import <UIImageView+WebCache.h>

#define kPicOneHeight 250 * kRelativelength_Y

@implementation WTPictureCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _picOneImageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth * 2 / 3, kPicOneHeight)];
        [self.contentView addSubview:_picOneImageV];
        
        _picTwoImageV = [[UIImageView alloc]initWithFrame:CGRectMake(_picOneImageV.right + kRelativeLength_X * 2, _picTwoImageV.top, kScreenWidth / 3 - 2 * kRelativeLength_X, (kPicOneHeight - 2 * kRelativelength_Y) / 2)];
        [self.contentView addSubview:_picTwoImageV];
        
        _picThrImageV = [[UIImageView alloc]initWithFrame:CGRectMake(_picTwoImageV.left, _picTwoImageV.bottom + 2 * kRelativelength_Y, _picTwoImageV.width, _picTwoImageV.height)];
        [self.contentView addSubview:_picThrImageV];
        
        
        // 放置标题和评论
        UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, _picOneImageV.bottom, kScreenWidth, 30 * kRelativelength_Y)];
        bgView.backgroundColor = [UIColor grayColor];
        bgView.alpha = 0.7;
        [self.contentView addSubview:bgView];
        
        // 标题
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * kRelativeLength_X, 0, 330 * kRelativeLength_X, bgView.height)];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        [bgView addSubview:_titleLabel];
        
        // 评论
        _commentLabel = [[UILabel alloc]initWithFrame:CGRectMake(_titleLabel.right, _titleLabel.top, kScreenWidth - _titleLabel.right, _titleLabel.height)];
        _commentLabel.textAlignment = NSTextAlignmentRight;
        [bgView addSubview:_commentLabel];
       
        
    }
    return self;
}


- (void)setModel:(WTPictureModel *)model
{
    _model = model;
    // 判断有几张图片
    // 1. 有一张
    // 2. 其他情况
    if ([model.imgSum isEqualToString:@"1"]) {
        _picOneImageV.frame = CGRectMake(0, 0, kScreenWidth, _picOneImageV.height);
        _picTwoImageV.hidden = YES;
        _picThrImageV.hidden = YES;
        
    }else {
        _picOneImageV.frame = CGRectMake(0, 0, kScreenWidth * 2 / 3, kPicOneHeight);
        _picTwoImageV.hidden = NO;
        _picThrImageV.hidden = NO;
    }

    
    [_picOneImageV sd_setImageWithURL:[NSURL URLWithString:model.picOne]];
    [_picTwoImageV sd_setImageWithURL:[NSURL URLWithString:model.picTwo]];
    [_picThrImageV sd_setImageWithURL:[NSURL URLWithString:model.picThr]];
   
    _titleLabel.text = model.title;
    _commentLabel.text = [NSString stringWithFormat:@"%@评论",model.commentNum];
    
    
}


@end
